package org.example.blog_system.controller;

import org.example.blog_system.model.BlogInfo;
import org.example.blog_system.model.UserInfo;
import org.example.blog_system.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/blog")
public class BlogController {

    @Autowired
    private BlogService blogService ;

    // 只需要查询所有的博客信息
    @RequestMapping("/getList")
    public List<BlogInfo> getList(){
        return blogService.getList();
    }
    @RequestMapping("/getBlog")
    public BlogInfo getBlog(Integer blogId){
        return blogService.getBlog(blogId);
    }
    // 接收博客
    @RequestMapping("/setBlog")
    public boolean setBlog(HttpSession session, BlogInfo blogInfo){
        return blogService.setBlog(session,blogInfo);
    }

    @RequestMapping("/updateBlog")
    public boolean updateBlog(BlogInfo blogInfo){

        boolean  flg =  blogService.updateBlog(blogInfo);

      return flg ;
    }

    @RequestMapping("/deleteBlog")
    public boolean deleteBlog(Integer blogId){
        boolean flg = blogService.deleteBlog(blogId);
        return flg ;
    }

    // 获取当前用户的博客数据
    @RequestMapping("/getBlogByUser")
    public Integer getBlogByUser(HttpSession session , Integer blogId){

       Integer n =   blogService.getBlogByUser(session , blogId);
        return n==null?0:n ;
    }

}
